package connector;

import cn.dai.util.CompleteJdbcUtils;
import cn.dai.util.HikariUtils;
import cn.dai.util.JdbcHikariUtil;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.junit.Test;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author ArkD42
 * @file Jdbc
 * @create 2020 - 04 - 24 - 23:26
 */
public class HikariTest {

    @Test
    public void hikariTest() throws Exception {
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl("jdbc:mysql:///jdbc_db?serverTimezone=Asia/Shanghai");
        config.setUsername("root");
        config.setPassword("123456");

        config.addDataSourceProperty("cachePrepStmts", "true");
        config.addDataSourceProperty("prepStmtCacheSize", "300");
        config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");

        HikariDataSource dataSource = new HikariDataSource(config);

        Connection connection = dataSource.getConnection();
        System.out.println(connection);
        connection.close();
    }

    @Test
    public void hikariTest2() throws Exception {
        final String configureFile = "src/main/resources/hikari.properties";
        HikariConfig configure = new HikariConfig(configureFile);
        HikariDataSource dataSource = new HikariDataSource(configure);
        Connection connection = dataSource.getConnection();
        System.out.println(connection);
        connection.close();
    }

    @Test
    public void hikariTest3() throws Exception {
        Connection connection = HikariUtils.getConnection();
        System.out.println(connection);
        connection.close();
    }

}
